﻿using System;
using System.Runtime.InteropServices;

namespace HslCommunication
{
	/// <summary>
	/// 用于网络传递的信息头，使用上等同于int
	/// </summary>
	/// <remarks>
	/// 通常用于<see cref="T:HslCommunication.Enthernet.NetComplexServer" />和<see cref="T:HslCommunication.Enthernet.NetComplexClient" />之间的通信，以及<see cref="T:HslCommunication.Enthernet.NetSimplifyServer" />和<see cref="T:HslCommunication.Enthernet.NetSimplifyClient" />通讯
	/// </remarks>
	/// <example>
	/// 使用上等同于int，只是本结构体允许将4字节的int拆分成3部分单独访问
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\NetHandle.cs" region="NetHandleExample" title="NetHandle示例" />
	/// </example>
	// Token: 0x0200000E RID: 14
	[StructLayout(LayoutKind.Explicit)]
	public struct NetHandle
	{
		/// <summary>
		/// 赋值操作，可以直接赋值int数据
		/// </summary>
		/// <param name="value">int数值</param>
		/// <returns>等值的消息对象</returns>
		// Token: 0x06000074 RID: 116 RVA: 0x00003F68 File Offset: 0x00002168
		public static implicit operator NetHandle(int value)
		{
			return new NetHandle(value);
		}

		/// <summary>
		/// 也可以赋值给int数据
		/// </summary>
		/// <param name="netHandle">netHandle对象</param>
		/// <returns>等值的消息对象</returns>
		// Token: 0x06000075 RID: 117 RVA: 0x00003F80 File Offset: 0x00002180
		public static implicit operator int(NetHandle netHandle)
		{
			return netHandle.m_CodeValue;
		}

		/// <summary>
		/// 判断是否相等
		/// </summary>
		/// <param name="netHandle1">第一个数</param>
		/// <param name="netHandle2">第二个数</param>
		/// <returns>等于返回<c>True</c>，否则<c>False</c></returns>
		// Token: 0x06000076 RID: 118 RVA: 0x00003F98 File Offset: 0x00002198
		public static bool operator ==(NetHandle netHandle1, NetHandle netHandle2)
		{
			return netHandle1.CodeValue == netHandle2.CodeValue;
		}

		/// <summary>
		/// 判断是否不相等
		/// </summary>
		/// <param name="netHandle1">第一个对象</param>
		/// <param name="netHandle2">第二个对象</param>
		/// <returns>等于返回<c>False</c>，否则<c>True</c></returns>
		// Token: 0x06000077 RID: 119 RVA: 0x00003FBC File Offset: 0x000021BC
		public static bool operator !=(NetHandle netHandle1, NetHandle netHandle2)
		{
			return netHandle1.CodeValue != netHandle2.CodeValue;
		}

		/// <summary>
		/// 两个数值相加
		/// </summary>
		/// <param name="netHandle1">第一个对象</param>
		/// <param name="netHandle2">第二个对象</param>
		/// <returns>返回两个指令的和</returns>
		// Token: 0x06000078 RID: 120 RVA: 0x00003FE4 File Offset: 0x000021E4
		public static NetHandle operator +(NetHandle netHandle1, NetHandle netHandle2)
		{
			return new NetHandle(netHandle1.CodeValue + netHandle2.CodeValue);
		}

		/// <summary>
		/// 两个数值相减
		/// </summary>
		/// <param name="netHandle1">第一个对象</param>
		/// <param name="netHandle2">第二个对象</param>
		/// <returns>返回两个指令的差</returns>
		// Token: 0x06000079 RID: 121 RVA: 0x0000400C File Offset: 0x0000220C
		public static NetHandle operator -(NetHandle netHandle1, NetHandle netHandle2)
		{
			return new NetHandle(netHandle1.CodeValue - netHandle2.CodeValue);
		}

		/// <summary>
		/// 判断是否小于另一个数值
		/// </summary>
		/// <param name="netHandle1">第一个对象</param>
		/// <param name="netHandle2">第二个对象</param>
		/// <returns>小于则返回<c>True</c>，否则返回<c>False</c></returns>
		// Token: 0x0600007A RID: 122 RVA: 0x00004034 File Offset: 0x00002234
		public static bool operator <(NetHandle netHandle1, NetHandle netHandle2)
		{
			return netHandle1.CodeValue < netHandle2.CodeValue;
		}

		/// <summary>
		/// 判断是否大于另一个数值
		/// </summary>
		/// <param name="netHandle1">第一个对象</param>
		/// <param name="netHandle2">第二个对象</param>
		/// <returns>大于则返回<c>True</c>，否则返回<c>False</c></returns>
		// Token: 0x0600007B RID: 123 RVA: 0x00004058 File Offset: 0x00002258
		public static bool operator >(NetHandle netHandle1, NetHandle netHandle2)
		{
			return netHandle1.CodeValue > netHandle2.CodeValue;
		}

		/// <summary>
		/// 初始化一个暗号对象
		/// </summary>
		/// <param name="value">使用一个默认的数值进行初始化</param>
		// Token: 0x0600007C RID: 124 RVA: 0x0000407A File Offset: 0x0000227A
		public NetHandle(int value)
		{
			this.m_CodeMajor = 0;
			this.m_CodeMinor = 0;
			this.m_CodeIdentifier = 0;
			this.m_CodeValue = value;
		}

		/// <summary>
		/// 根据三个值来初始化暗号对象
		/// </summary>
		/// <param name="major">主暗号</param>
		/// <param name="minor">次暗号</param>
		/// <param name="identifier">暗号编号</param>
		// Token: 0x0600007D RID: 125 RVA: 0x00004099 File Offset: 0x00002299
		public NetHandle(byte major, byte minor, ushort identifier)
		{
			this.m_CodeValue = 0;
			this.m_CodeMajor = major;
			this.m_CodeMinor = minor;
			this.m_CodeIdentifier = identifier;
		}

		/// <summary>
		/// 完整的暗号值
		/// </summary>
		// Token: 0x1700003A RID: 58
		// (get) Token: 0x0600007E RID: 126 RVA: 0x000040B8 File Offset: 0x000022B8
		// (set) Token: 0x0600007F RID: 127 RVA: 0x000040C0 File Offset: 0x000022C0
		public int CodeValue
		{
			get
			{
				return this.m_CodeValue;
			}
			set
			{
				this.m_CodeValue = value;
			}
		}

		/// <summary>
		/// 主暗号分类0-255
		/// </summary>
		// Token: 0x1700003B RID: 59
		// (get) Token: 0x06000080 RID: 128 RVA: 0x000040C9 File Offset: 0x000022C9
		// (set) Token: 0x06000081 RID: 129 RVA: 0x000040D1 File Offset: 0x000022D1
		public byte CodeMajor
		{
			get
			{
				return this.m_CodeMajor;
			}
			private set
			{
				this.m_CodeMajor = value;
			}
		}

		/// <summary>
		/// 次要的暗号分类0-255
		/// </summary>
		// Token: 0x1700003C RID: 60
		// (get) Token: 0x06000082 RID: 130 RVA: 0x000040DA File Offset: 0x000022DA
		// (set) Token: 0x06000083 RID: 131 RVA: 0x000040E2 File Offset: 0x000022E2
		public byte CodeMinor
		{
			get
			{
				return this.m_CodeMinor;
			}
			private set
			{
				this.m_CodeMinor = value;
			}
		}

		/// <summary>
		/// 暗号的编号分类0-65535
		/// </summary>
		// Token: 0x1700003D RID: 61
		// (get) Token: 0x06000084 RID: 132 RVA: 0x000040EB File Offset: 0x000022EB
		// (set) Token: 0x06000085 RID: 133 RVA: 0x000040F3 File Offset: 0x000022F3
		public ushort CodeIdentifier
		{
			get
			{
				return this.m_CodeIdentifier;
			}
			private set
			{
				this.m_CodeIdentifier = value;
			}
		}

		/// <summary>
		/// 获取完整的暗号数据
		/// </summary>
		/// <returns>返回暗号的字符串表示形式</returns>
		// Token: 0x06000086 RID: 134 RVA: 0x000040FC File Offset: 0x000022FC
		public override string ToString()
		{
			return this.m_CodeValue.ToString();
		}

		/// <summary>
		/// 判断两个实例是否相同
		/// </summary>
		/// <param name="obj">对比的对象</param>
		/// <returns>相同返回<c>True</c>，否则返回<c>False</c></returns>
		// Token: 0x06000087 RID: 135 RVA: 0x0000411C File Offset: 0x0000231C
		public override bool Equals(object obj)
		{
			NetHandle netHandle;
			bool flag;
			if (obj is NetHandle)
			{
				netHandle = (NetHandle)obj;
				flag = true;
			}
			else
			{
				flag = false;
			}
			bool flag2 = flag;
			return flag2 && this.CodeValue.Equals(netHandle.CodeValue);
		}

		/// <summary>
		/// 获取哈希值
		/// </summary>
		/// <returns>返回当前对象的哈希值</returns>
		// Token: 0x06000088 RID: 136 RVA: 0x00004160 File Offset: 0x00002360
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		/// <summary>
		/// 完整的暗号值
		/// </summary>
		// Token: 0x04000047 RID: 71
		[FieldOffset(0)]
		private int m_CodeValue;

		/// <summary>
		/// 主暗号分类0-255
		/// </summary>
		// Token: 0x04000048 RID: 72
		[FieldOffset(3)]
		private byte m_CodeMajor;

		/// <summary>
		/// 次要的暗号分类0-255
		/// </summary>
		// Token: 0x04000049 RID: 73
		[FieldOffset(2)]
		private byte m_CodeMinor;

		/// <summary>
		/// 暗号的编号分类0-65535
		/// </summary>
		// Token: 0x0400004A RID: 74
		[FieldOffset(0)]
		private ushort m_CodeIdentifier;
	}
}
